package cn.lhjl.day09.reflect;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

public class Practice {
    public static void main(String[] args) {
        //创建能够加载字节流的Properties集合来读配置文件
        Properties pro = new Properties();
        ClassLoader classLoader = Practice.class.getClassLoader();
        InputStream is = classLoader.getResourceAsStream("pro.properties");//pro中className是全类名
        try {
            pro.load(is);
            String className = pro.getProperty("className");
            String methodName = pro.getProperty("methodName");
            Class cls = Class.forName(className);
            Object o = cls.newInstance();
            Method method1 = cls.getMethod(methodName);
            method1.invoke(o);


        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}
